using System;
using System.Net;

namespace InfoCenter.Agent.Entities
{
    /// <summary>
    /// Represent a computer
    /// </summary>
    public class Computer
    {
        #region private fields
        private string _name;
        private string _ip;
        private string _userName;
        private string _osVersion;
        #endregion

        #region public properties
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Ip
        {
            get { return _ip; }
            set { _ip = value; }
        }

        public string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }

        public string OsVersion
        {
            get { return _osVersion; }
            set { _osVersion = value; }
        }
        #endregion

        /// <summary>
        /// Return computer instance
        /// </summary>
        /// <returns></returns>
        public static Computer Create()
        {
            Computer computer = new Computer();

            computer.Name = Environment.MachineName;

            //get ip
            foreach (IPAddress ip in Dns.GetHostAddresses(computer.Name))
            {
                if (((ip != IPAddress.Any) || (ip != IPAddress.Loopback)) &&
                    (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork))
                {
                    computer.Ip = ip.ToString();
                }
            }

            computer.UserName = Environment.UserName;
            computer.OsVersion = Environment.OSVersion.ToString();

            return computer;
        }

        

    }
}
